//
//	 ______    ______    ______    
//	/\  __ \  /\  ___\  /\  ___\   
//	\ \  __<  \ \  __\_ \ \  __\_ 
//	 \ \_____\ \ \_____\ \ \_____\ 
//	  \/_____/  \/_____/  \/_____/ 
//
//	Powered by BeeFramework
//
//
//  MeetingCreateBoard.m
//  iHeima
//
//  Created by he chao on 5/28/14.
//  Copyright (c) 2014 leon. All rights reserved.
//

#import "MeetingCreateBoard.h"
#import "MeetingInviteBoard.h"

#pragma mark -

@interface MeetingCreateBoard()
{
	//<#@private var#>
}
@end

@implementation MeetingCreateBoard
DEF_SIGNAL(CREATE)
DEF_SIGNAL(CLEAR)

- (void)load
{
}

- (void)unload
{
}

#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"召开私董会";
    self.navigationController.navigationBarHidden = NO;
    [self showBarButton:BeeUINavigationBar.LEFT title:@"取消"];
    [self showNaviBar];
    [self loadContent];
}

ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

ON_DID_APPEAR( signal )
{
    
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.stack popBoardAnimated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
}

ON_SIGNAL2(MeetingCreateBoard, signal){
    if ([signal is:MeetingCreateBoard.CREATE]) {
        if (field.text.length==0) {
            [[BeeUITipsCenter sharedInstance] presentMessageTips:@"请输入会议主题"];
            return;
        }
        BeeHTTPRequest *request = [self POST:[NSString stringWithFormat:@"%@/apichat/addboard",kBaseUrl]].PARAM(@"uid",kUserInfo[@"uid"]).PARAM(@"title",field.text).PARAM(@"anonymous",_switch[0].on?@"1":@"0").PARAM(@"opentype",_switch[1].on?@"1":@"2");
        request.tag = 9527;
        //[self.stack pushBoard:[[MeetingInviteBoard alloc] init] animated:YES];
    }
    else if ([signal is:MeetingCreateBoard.CLEAR]) {
        [field resignFirstResponder];
    }
}

- (void)handleRequest:(BeeRequest *)request
{
    if(request.failed)
    {
        [[BeeUITipsCenter sharedInstance] dismissTips];
        NETWORK_ERROR
    }
    else if (request.succeed)
    {
        id json = [request.responseString mutableObjectFromJSONString];
        NSLog(@"%@",json);
        switch ([json[@"status"] intValue]) {
            case 1:
            {
                switch (request.tag) {
                    case 9527:
                    {
                        MeetingInviteBoard *board = [[MeetingInviteBoard alloc] init];
                        board.strMeetingId = json[@"res"];
                        [self.stack pushBoard:board animated:YES];
                    }
                        break;
                }
            }
        }
    }
}

- (void)resigh:(UITextField*)sender{

    [sender resignFirstResponder];
    
}

- (void)loadContent{
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view makeTappable:MeetingCreateBoard.CLEAR];
    
    UIImage *imgNote = IMAGESTRING(@"create_meeting_note");
    BeeUIImageView *imgV = [BeeUIImageView spawn];
    imgV.frame = CGRectMake(0, 0, imgNote.size.width, imgNote.size.height);
    imgV.center = CGPointMake(self.viewWidth/2.0, 50+imgV.height/2.0);
    imgV.image = imgNote;
    [self.view addSubview:imgV];
    
    field = [BeeUITextField spawn];
    field.frame = CGRectMake(37, imgV.bottom+30, 245, 40);
    field.backgroundColor = RGB(247, 247, 247);
    field.placeholder = @"填写一个会议主题";
    field.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 0)];
    field.leftViewMode = UITextFieldViewModeAlways;
    field.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    [self.view addSubview:field];
    field.returnKeyType = UIReturnKeyDone;
    [field addTarget:self action:@selector(resigh:) forControlEvents:UIControlEventEditingDidEndOnExit];
    
    for (int i = 0; i < 2; i++) {
        BaseLabel *lb = [BaseLabel initLabel:i==0?@"是否亮灯:":@"自由加入:" font:FONT(14) color:RGB(22, 158, 255) textAlignment:NSTextAlignmentLeft];
        lb.frame = CGRectMake(75, field.bottom+20+i*45, 80, 30);
        [self.view addSubview:lb];
        
        _switch[i] = [BeeUISwitch spawn];
        _switch[i].frame = CGRectMake(175, lb.top, _switch[i].width, _switch[i].height);
        [self.view addSubview:_switch[i]];
    }
    
    BaseButton *btnCreate = [BaseButton initBaseBtn:IMAGESTRING(@"create_meeting_btn") highlight:IMAGESTRING(@"create_meeting_btn_pre")];
    btnCreate.frame = CGRectMake((self.viewWidth-89)/2.0, _switch[1].bottom+20, 89, 88);
    [btnCreate addSignal:MeetingCreateBoard.CREATE forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnCreate];
    
    BaseLabel *lb = [BaseLabel initLabel:@"按一下,立即召集在线的黑马兄弟" font:FONT(14) color:kNormalColor textAlignment:NSTextAlignmentCenter];
    lb.frame = CGRectMake(0, btnCreate.bottom+10, self.viewWidth, 30);
    [self.view addSubview:lb];
}

@end
